﻿using cap01.Common.Util;
using StackExchange.Redis;

namespace cap01.Common.Redis;

public class RedisClient
{
	public static IDatabase Database { get; }

	public static ConnectionMultiplexer Redis { get; }

	public static IServer Server { get; set; }

	static RedisClient()
	{
		var connection = AppConfig.Settings.RedisConnection;
		try
        {
            Redis = ConnectionMultiplexer.Connect(connection);
            Database = Redis.GetDatabase();
            Server = Redis.GetServer(Redis.GetEndPoints()[0]);
        }
		catch (Exception e)
		{
			LoggerHelper.Error(e, "Redis连接错误。");
			throw;
		}
	}
}